<?php
$protocol = is_ssl() ? 'https' : 'http';
$uri = "{$protocol}://{$_SERVER['HTTP_HOST']}/addons/zjhj_wdds/core/?m=Home&c=pay&a=notify";

$data = array();
$post_data = file_get_contents("php://input");
file_put_contents('wechat-notify-1.log', "{$post_data}\n", FILE_APPEND);
$data = (array)simplexml_load_string($post_data, 'SimpleXMLElement', LIBXML_NOCDATA);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return = curl_exec($ch);
curl_close($ch);

echo $return;
exit;

function is_ssl()
{
  if (isset($_SERVER['HTTPS'])) {
    if ('on' == strtolower($_SERVER['HTTPS'])) {
      return true;
    }
    if ('1' == $_SERVER['HTTPS']) {
      return true;
    }
  } elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
    return true;
  }

  if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
    return true;
  }

  return false;
}